<template>
  <el-dialog :title="'支付配置'"
             :close-on-click-modal="false"
             :visible.sync="visible"
             width="80%">
    <div>
      <el-form label-width="160px" :model="dataForm" :rules="dataRule" ref="dataForm"  @keyup.enter.native="dataFormSubmit()">
        <el-form-item label="运营商名称：" prop="name">
          <el-input :disabled="true" v-model="dataForm.name" placeholder="请输入运营商名称" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="运营商LOGO" prop="logo">
          <pic-upload :disabled="true" v-model="dataForm.logo"></pic-upload>
        </el-form-item>
        <el-form-item label="联系人姓名" prop="contactsName">
          <el-input :disabled="true" v-model="dataForm.contactsName" placeholder="请输入联系人姓名" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="联系人电话" prop="contactsMobile">
          <el-input :disabled="true" v-model="dataForm.contactsMobile" placeholder="请输入联系人电话" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="乐刷商户名称">
          <el-input v-model="dataForm.merName" placeholder="请输入商户名称" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="乐刷商户号">
          <el-input v-model="dataForm.thirdPayMerId" placeholder="请输入商户号" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="乐刷分账开关" size="mini">
          <el-radio-group v-model="dataForm.isSplit">
            <el-radio :label="0">关闭</el-radio>
            <el-radio :label="1">开启</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="留存金额">
          <el-input v-model="dataForm.remainAmount" placeholder="留存金额" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="提现最大金额">
          <el-input-number v-model="dataForm.cashLimitMoney" @change="handleChange" :min="0" :max="50000" label="提现最大金额"></el-input-number>
        </el-form-item>
        <el-form-item label="退款开关" size="mini">
          <el-radio-group v-model="dataForm.refundSwitch">
            <el-radio :label="0">关闭</el-radio>
            <el-radio :label="1">开启</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="最大退款金额(超过此金额需手动退款)">
          <el-input v-model="dataForm.refundLimitMoney" placeholder="最大退款金额" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item label="合伙人提现手续费（%）">
          <el-input v-model="dataForm.cashRate" placeholder="合伙人提现手续费" style="width: 50%"></el-input>
        </el-form-item>
        <el-form-item class="footer">
          <el-button type="primary" @click.stop="dataFormSubmit">提交</el-button>
          <el-button type="primary" plain @click.stop="close">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>

<script>
  import picUpload from '@/components/pic-upload/index.vue'
  export default {
    name: "merchant-thirdpay-config",
    components: {
      picUpload
    },
    data () {
      return {
        visible: false,
        dataForm: {
          id: '',
          name: '',
          logo: '',
          contactsName: '',
          contactsMobile: '',
          merName: '',
          thirdPayMerId: '',
          isSplit: '',
          remainAmount: '',
          cashLimitMoney:'',
          refundSwitch:'',
          refundLimitMoney:'',
          cashRate:'',
        },
        dataRule: {
          thirdPayMerId: [
            { required: true, message: '商户id不能为空', trigger: 'blur' }
          ],
          merName: [
            { required: true, message: '商户名称不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (row) {
        if (row) {
          this.dataForm = row
        }
        this.visible = true
      },
      handleChange(value) {
        console.log(value);
      },
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl('/v1/merchant/third/pay/binding/mer/id'),
              method: 'post',
              data: this.$http.adornData(this.dataForm)
            }).then(({ data }) => {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList', this.page)
                }
              })
            })
          }
        })
      },

      close () {
        this.$refs['dataForm'].resetFields()
        this.visible = false
      }
    }
  }
</script>

<style lang="scss" scoped>
  .seciont-1{
    padding: 0px 0px 15px 0px;
    margin-bottom: 12px;
    color: #333333;
    font-weight: bold;
    border-bottom:  solid 1px #DADADA;
  }
  .footer{
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
